package com.atguigu.lease.common.springmvc;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandlers {
    //        public static  Result<String> fail(String message) {
//            Result<String> result = build(null);
//            result.setCode(ResultCodeEnum.FAIL.getCode());
//            result.setMessage(message);      错误信息
//            return result;
//        }
    @ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception e) {

//记录日志
        e.printStackTrace();
        //返回提示
        return Result.fail(e.getMessage());
    }
    //接受自定义异常
    @ExceptionHandler(leaseException.class)
    public Result<String> leaseExceptionHandler(leaseException e) {
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMessage());
    }
}